<?php

namespace App\Models;
class MallRefund extends Base
{
    const STATUS_WAIT_REFUND = 1;
    const STATUS_DELIVER_PRODUCT = 2;
    const STATUS_REFUND_ING = 3;
    const STATUS_CANCEL = 4;
    const STATUS_REFUSE = 5;
    const STATUS_REFUND_SUCCESS = 6;

    protected $casts = [
        'file' => 'array',
    ];

    protected $appends = ['actual_amount_yuan', 'fare_yuan', 'paid_amount_yuan'];

    public function order_product() {
        return $this->belongsTo(MallOrderProduct::class, 'order_product_id');
    }

    public function product() {
        return $this->belongsTo(MallOrderProductSnapshot::class, 'product_snapshot_id');
    }

    public function getActualAmountYuanAttribute() {
        return format_yuan($this->actual_amount);
    }

    public function getPaidAmountYuanAttribute() {
        return format_yuan($this->paid_amount);
    }

    public function getFareYuanAttribute() {
        return format_yuan($this->fare);
    }

    public function user() {
        return $this->belongsTo(User::class, 'user_id');
    }

    public function category() {
        return $this->belongsTo(Category::class, 'category_id');
    }

    public function setFileAttribute($val) {
        $this->attributes['file'] = $val;
    }

}
